package com.example.testanimation;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.testanimation.javabean.Courses;


public class SelectClass extends AppCompatActivity {
    private MySQLiteOpenHelper1 mySQLiteOpenHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Compiler EdgeToEdge = null;
        EdgeToEdge.enable();
        setContentView(R.layout.activity_select_class);
        mySQLiteOpenHelper = new MySQLiteOpenHelper1(this);

    }
    public void btn1(View view) {
        Courses cour = new Courses("Javaweb      ","黑老师","周四 8:00-10:00","教学楼201室");

        // 使用AlertDialog询问用户是否确认添加
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("确认添加")
                .setMessage("您确定要添加这门课程吗？")
                .setPositiveButton("确认", (dialog, which) -> {
                    // 用户点击确认，执行添加操作
                    long register = mySQLiteOpenHelper.register(cour);
                    if (register != -1) {
                        Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "添加失败，你已经选择过此课程", Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    // 用户点击取消，不执行任何操作，对话框关闭
                    dialog.cancel();
                })
                .create()
                .show();
    }
    public void but2(View view) {
        Courses cour = new Courses("安卓开发基础教程","马老师","周五 12:00-14:00","教学楼203室");

        // 使用AlertDialog询问用户是否确认添加
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("确认添加")
                .setMessage("您确定要添加这门课程吗？")
                .setPositiveButton("确认", (dialog, which) -> {
                    // 用户点击确认，执行添加操作
                    long register = mySQLiteOpenHelper.register(cour);
                    if (register != -1) {
                        Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "添加失败，你已经选择过此课程", Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    // 用户点击取消，不执行任何操作，对话框关闭
                    dialog.cancel();
                })
                .create()
                .show();
    }
    public void but3(View view) {
        Courses cour = new Courses("C++开发基础教程","龙老师","周二 15:00-17:00","教学楼212室");

        // 使用AlertDialog询问用户是否确认添加
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("确认添加")
                .setMessage("您确定要添加这门课程吗？")
                .setPositiveButton("确认", (dialog, which) -> {
                    // 用户点击确认，执行添加操作
                    long register = mySQLiteOpenHelper.register(cour);
                    if (register != -1) {
                        Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "添加失败，你已经选择过此课程", Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    // 用户点击取消，不执行任何操作，对话框关闭
                    dialog.cancel();
                })
                .create()
                .show();
    }
    public void but4(View view) {
        Courses cour = new Courses("java开发基础教程","王老师","周一 08:00-10:00","教学楼201室");

        // 使用AlertDialog询问用户是否确认添加
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("确认添加")
                .setMessage("您确定要添加这门课程吗？")
                .setPositiveButton("确认", (dialog, which) -> {
                    // 用户点击确认，执行添加操作
                    long register = mySQLiteOpenHelper.register(cour);
                    if (register != -1) {
                        Toast.makeText(this, "添加成功", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "添加失败，你已经选择过此课程", Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", (dialog, which) -> {
                    // 用户点击取消，不执行任何操作，对话框关闭
                    dialog.cancel();
                })
                .create()
                .show();
    }
    }
